document.oncontextmenu = function() {
//	return false;
};

//屏蔽backspace键
if(document.addEventListener){
    document.addEventListener("keydown",maskBackspace, true);
}else{
    document.attachEvent("onkeydown",maskBackspace);
}
function maskBackspace(event){
    var event = event || window.event;  //标准化事件对象
    var obj = event.target || event.srcElement;
    var keyCode = event.keyCode ? event.keyCode : event.which ?
            event.which : event.charCode;
    if(keyCode == 8){
        if(obj!=null && obj.tagName!=null && (obj.tagName.toLowerCase() == "input"  
               || obj.tagName.toLowerCase() == "textarea")){
            event.returnValue = true ;
            if(Ext.getCmp(obj.id)){
                if(Ext.getCmp(obj.id).readOnly) {
                    if(window.event)
                        event.returnValue = false ;  //or event.keyCode=0
                    else
                        event.preventDefault();   //for ff[/b]
                }
            }
        }else{
            if(window.event)
                event.returnValue = false ;   // or event.keyCode=0
            else
                event.preventDefault();    //for ff
        }
    }
}
//屏蔽backspace键

// modify by thd
var fzjf_privData;
var getPrivilegeDot = function(privIds) {
	Ext.Ajax.request({
		url: 'privilegeAction.do?action=judgePrivilege&search.privIds=' + privIds,
		method: 'post',
		async: false,
		callback: function(options, success, response) {
			fzjf_privData = (Ext.decode(response.responseText)).privilege;
		}
	});
	
	return fzjf_privData;
}

Array.prototype.contains = function(obj) {
	var i = this.length;
	
    while (i--) {
    	if (this[i] === obj) {
    		return true;
    	}
    }
    
    return false;
}

var replaceNull = function(val) {
	return val == null ? "" : val;
}

//modify by thd --- start
/**
 * instance：数据，json对象
 * grid：需要被操作的GridPanel
 */
var add2grid = function(instance, grid) {
	var col = '';
	var val = '';
	
	try {
		for (var key in instance) {
			col += ',{name:\'' + key + '\'}';
			val += ',' + key + ': \'' + replaceNull(instance[key]) + '\'';
		}
		col = col.substring(1);
		val = val.substring(1);
		
		var colRecord = eval('Ext.data.Record.create([' + col + '])');
		var record = eval('new colRecord({' + val + '})');
		
		grid.getStore().insert(0, record);
		grid.getSelectionModel().selectFirstRow();
		
		//refresh pagebar
		refreshPageBar(1, grid.getBottomToolbar());
	} catch (e) {}
}

/**
 * instance：数据，json对象
 * grid：需要被操作的GridPanel
 */
var mod2grid = function(instance, grid) {
	var record = grid.getSelectionModel().getSelected();
	
	for (var key in instance) {
		eval('record.set(\'' + key + '\', \'' + replaceNull(instance[key]) + '\')');
	}
	
	record.commit();
}

/**
 * grid：需要被操作的GridPanel
 */
var del2grid = function (grid) {
	var recordArr = grid.getSelectionModel().getSelections();
	
	for (var i = 0; i < recordArr.length; i++) {
		grid.getStore().remove(recordArr[i]);
	}
	
	//refresh pagebar
	refreshPageBar(eval('-' + recordArr.length), grid.getBottomToolbar());
}

/**
 * 清除自定义的分页条缓存
 * @return
 */
var clearCache4PageBar = function() {
	try {
		this.thd = undefined;
	} catch (e) {}
}

/**
 * 刷新分页条统计信息
 * @param count 一次刷新操作的记录数
 * @param pageBar 分页条对象
 * @return
 */
var refreshPageBar = function(count, pageBar) {
	try {
		var displayMsg = pageBar.displayMsg;
		var emptyMsg = pageBar.emptyMsg;
		
		if (this.thd == undefined) {
			this.thd = new Object();
			
			var total = pageBar.getPageData().total;
			var activePage = pageBar.getPageData().activePage;
			var pages = pageBar.getPageData().pages;
			var pageSize = pageBar.pageSize;
			
			var start = (activePage - 1) * pageSize + 1;
			var end = total;
			
			if (activePage != pages) {
				end = start + pageSize - 1;
			}			
		} else {
			var total = this.thd.total;
			var start = this.thd.start;
			var end = this.thd.end;
		}
		
		if ((count + end - start + 1) <= 0) {
			pageBar.displayItem.update(emptyMsg);
		} else {
			if (displayMsg.indexOf('{0}') != -1) {
				displayMsg = displayMsg.replace('{0}', start);
			}
			
			if (displayMsg.indexOf('{1}') != -1) {
				displayMsg = displayMsg.replace('{1}', end + count);
			}
			
			if (displayMsg.indexOf('{2}') != -1) {
				displayMsg = displayMsg.replace('{2}', total + count);
			}
			
			pageBar.displayItem.update(displayMsg);
		}
		
		this.thd.total = (total + count);
		this.thd.start = start;
		this.thd.end = (end + count);
	} catch (e) {}
}
//modify by thd --- end


//if (window.top.location != getSitePath() + '/'
//		&& window.top.location != getSitePath() + '/index.jsp') {
//	window.top.location.href = getSitePath();
//}
// 设置某gird可选
function selectable(grid) {
	var s = grid.body.dom.getElementsByTagName('div');
	for (var i = 0; i < s.length; i++) {
		s[i].unselectable = 'off';
	}
}
function getSitePath() {
	var B = document.location.protocol, C = document.location.host, D = document.location.pathname, A = document.location.search, E = B
			+ "//" + C + "/" + (D.split("/"))[1];
	return E;
}

function isPurview(res, validRes) {
	if (!validRes || validRes[res] === undefined) {
		return true;
	}
	return false;
}

String.prototype.trim = function() {
	var pattern = /(^\s*)|(\s*$)/g;
	return this.replace(pattern, "");
};

function isPassword(passwordText) {
	if (passwordText.search(/[^a-z\d]/i) >= 0) {
		return false;
	}
	if (passwordText.search(/\d/) < 0) {
		return false;
	}
	if (passwordText.search(/[a-z]/i) < 0) {
		return false;
	}
	return true;
}
function isInteger(integer) {
	var pattern = /^(?:(?:[1-9]\d*)|0)$/;
	if (integer.search(pattern) < 0) {
		return false;
	}
	return true;
}
function isNumberText(number) {
	var pattern = /\D/;
	if (number.search(pattern) >= 0) {
		return false;
	}
	return true;
}
function isReal(real) {
	var pattern = /^(?:(?:[1-9]\d*)|0)(?:\.\d+)?$/;
	if (real.search(pattern) < 0) {
		return false;
	}
	return true;
}

function getCookie(key) {
	var cookiesArr = document.cookie.split(";");
	for (var i = 0; i < cookiesArr.length; i++) {
		var arr = cookiesArr[i].split("=");
		if (arr[0] == key) {
			return arr[1];
		}
	}
	return '';
}

function getHelpButton() {
	var helpwin = new Ext.Window({
				iconCls : 'icon-grid',
				title : "帮助信息",
				width : 500,
				height : 400,
				html : ''
			});
	helpwin.show();
}


﻿﻿﻿﻿﻿﻿Ext.apply(Ext.form.VTypes, { 
	daterange : function(val, field) { 
	var date = field.parseDate(val); 
	if (!date) { 
	return; 
	} 
	if (field.startDateField 
	&& (!this.dateRangeMax || (date.getTime() != this.dateRangeMax 
	.getTime()))) { 
	var start = Ext.getCmp(field.startDateField); 
	start.setMaxValue(date); 
	start.validate(); 
	this.dateRangeMax = date; 
	} else if (field.endDateField 
	&& (!this.dateRangeMin || (date.getTime() != this.dateRangeMin 
	.getTime()))) { 
	var end = Ext.getCmp(field.endDateField); 
	end.setMinValue(date); 
	end.validate(); 
	this.dateRangeMin = date; 
	} 
	
	               
	return true; 
	           
	} 
	        
	});





